package itheima_Integer;

public class Integer_find03 {
    public static void main(String[] args) {

        int[] arr = {12, 32, 45, 56, 58, 60};
        int i = 32;
        int index = bianarySearch(arr, i);
        System.out.println(i + "在数组中索引位置的数是" + index);

    }
    private static int bianarySearch(int[] arr, int i) {

        int min = 0, max = arr.length - 1;
        while (min <= max) {
            int mid = (min + max) / 2;
            if (arr[mid] < i) {
                min = mid + 1;
            } else if (arr[mid] > i) {
                max = mid - 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
}
